package com.cmcc.pcap.packet.udp.quic;

import com.cmcc.packet.entity.QuicEntity;
import com.cmcc.packet.entity.UdpEntity;
import com.cmcc.pcap.packet.udp.UdpConnection;
import com.cmcc.pcap.packet.udp.UdpProtocolHandler;
import com.cmcc.pcap.packet.udp.quic.xdr.QuicXdrGenerate;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Date;
import java.util.List;

/**
 * @Auther: zhida wei
 * @Date: 2019/6/17 18:06
 * @Description:
 */
public class QuicHandler extends UdpProtocolHandler<QuicEntity> {
    private static Logger logger = LogManager.getLogger(QuicHandler.class);
    private QuicXdrGenerate qxg;

    public QuicHandler() {
        qxg =  new QuicXdrGenerate();
    }

    @Override
    public List<QuicEntity> handle(UdpConnection udpConnection, String taskId) {
        logger.debug("start execute quic packet handler");

        logger.debug(new Date(udpConnection.lastPacketTime));//最后一个packet的处理时间(注:非抓包时间)
        long pcapTimestamp  = udpConnection.lastPacketTime;//pcap的timestamp的单位是秒，这里需要转成毫秒
        logger.debug(new Date(pcapTimestamp));//最后一个packet的抓包时间


        List<QuicEntity> xdrquicEntityList = qxg.generate(udpConnection,taskId);
        logger.debug("this connection <"+udpConnection.connectionKey+"> save into quic packet entity !");

        return xdrquicEntityList;

    }
}
